<template>
	<!-- 科普 -->
	<view>
		<view class="tab">
			<!-- <scroll-view class="ta-box" >
				<view class="ta-one" @click="tabFn(v,i)" :class="{active:tabIndex==i}" v-for="(v,i) in tabList"
					:key="i">{{v.name}}</view>
			</scroll-view> -->
			<u-tabs :list="tabList" @click="tabFn" lineColor="#000" :current='index'
				:activeStyle="{color: ' #1A1A1A',fontWeight: 'bold',fontSize:'32rpx',transform: 'scale(1.05)'}"></u-tabs>
			<view class="ta-search">
				<image src="../static/img/search.png" mode=""></image>
				<input placeholder="搜索科普" disabled @click="_to" />
			</view>
		</view>

		<c-scroll-list ref="list" :api="getApi" :apiParams="apiParams" :option="option" @load="(res)=>(list=res)">
			<view class="main">
				<view class="ma-box" @click="jumpDetails(v.id)" v-for="v in list.list" :key="v.id">
					<view class="ma-left">
						<view class="ma-title otw">{{v.title}}</view>
						<view class="ma-subTitle otw">{{v.subhead}}</view>
						<view class="ma-heat">
							<view class="">作者：{{v.author}}</view>
							<view class="">{{v.readNum}}阅读</view>
						</view>
					</view>
					<view class="ma-right">
						<image class="ma-img" :src="vuex_imgUrl+v.picture" mode=""></image>
					</view>
				</view>
			</view>
		</c-scroll-list>

	</view>
</template>

<script>
	export default {
		data() {
			return {

				getApi: this.$api.scienceListQ,
				index: 0,
				apiParams: {
					categoryId: ''
				},
				list: [],
				tabIndex: 0,
				tabList: [{
					name: '全部',
				}, {
					name: '科普1',
				}, {
					name: '科普2',
				}, ]
			}
		},
		onLoad(options) {
			this.apiParams.categoryId = options.id
			this.index = options.index;

			this.getMenu()

		},
		methods: {
			// 跳转到
			_to() {
				uni.navigateTo({
					url: "/pages/my/pages/search"
				})
			},
			// 获取tab列表
			getMenu() {
				this.$api.scienceMenuQ().then(res => {
					res.data.forEach(item => {
						this.tabList.push(item)
					})

				})
			},
			// 切换tab
			tabFn(item) {
				console.log(item, '00');
				this.apiParams.categoryId = item.id
				this.$refs.list.refresh();

			},
			// 跳转到详情
			jumpDetails(id) {
				uni.navigateTo({
					url: `/pages/my/pages/popularScienceDetails?id=${id}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	/deep/.u-tabs__wrapper__scroll-view-wrapper.data-v-48634e29 {
		width: 470rpx;
		margin-left: -20rpx;
	}

	.bg {
		width: 750rpx;
		height: 320rpx;
		background: linear-gradient(180deg, #E6F5F4 0%, #FFFFFF 100%);
		position: absolute;
		z-index: -1;
		top: 0;
	}

	.tab {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx 32rpx 16rpx;
		border-bottom: 8rpx solid #F5F5F5;

		.ta-box {
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: space-around;
			overflow-y: scroll;

			.ta-one {
				font-size: 28rpx;
				font-weight: 400;
				color: #666666;

				&.active {
					font-size: 32rpx;
					font-weight: bold;
					color: #1A1A1A;
					position: relative;

					&::after {
						width: 100%;
						height: 6rpx;
						background: #1A1A1A;
						border-radius: 6rpx;
						display: inline-block;
						content: '';
						position: absolute;
						bottom: -15rpx;
						left: 0;
					}
				}
			}
		}

		.ta-search {
			width: 200rpx;
			height: 56rpx;
			background: #F5F5F5;
			border-radius: 40rpx;
			flex: none;
			margin-left: 30rpx;
			display: flex;
			align-items: center;

			image {
				width: 20rpx;
				height: 20rpx;
				flex: none;
				padding-right: 12rpx;
				margin-left: 20rpx;
			}

			input {
				font-size: 20rpx;
				font-weight: 400;
				color: #999999;
			}
		}
	}

	.main {
		.ma-box {
			padding: 28rpx 0 24rpx;
			margin: 0 32rpx;
			display: flex;
			border-bottom: 1rpx solid #E6E6E6;

			.ma-left {
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.ma-title {
					font-size: 32rpx;
					color: #333333;
				}

				.ma-subTitle {
					font-size: 24rpx;
					font-weight: 400;
					color: #666666;
				}

				.ma-heat {
					display: flex;
					justify-content: space-between;
					font-size: 20rpx;
					font-weight: 400;
					color: #999999;
				}
			}

			.ma-right {
				width: 200rpx;
				height: 150rpx;
				background: #D9D9D9;
				border-radius: 8rpx;
				flex: none;
				margin-left: 40rpx;

				.ma-img {
					width: 100%;
					height: 100%;
				}
			}
		}
	}
</style>